'''
typeAll = ['jpg','png','jpeg']


class FileTypeError(Exception):
    def __init__(self, error):
        self.error = error


try:
    file_name = input('请输入文件:')
    index = file_name.find(".")
    type = file_name[index + len('.'):]
    if type not in typeAll:
        raise FileExistsError('您输入的文件格式错误')
    
    print('上传成功！')
except FileExistsError as error:
    print('出错了,原因是:',error)








class QuantityError(Exception):
    def __init__(self, error):
        self.error = error

def shopping():
    goods_dict={'香蕉':10.0, '苹果':12.0, '梨':16.0, '西瓜':8.0}
    all_goods = {}
    all_prices = 0
    while True:
        print('*************************')
        print('*** 1.香蕉(1): 10.0元 ***')
        print('*** 2.苹果(2): 12.0   ***')
        print('*** 3.西瓜(3): 8.0元  ***')
        print('*** 4.梨(4): 16.0元   ***')
        print('***     5.退出(0)     ***')
        print('*************************')


        goods_name = input("请输入商品名称(退出请按0):")

        if goods_name == '0':
            print(all_goods)
            print('您已经购买了,')
            for key, value in all_goods.items():
                print(key + ': ' + value + "个")
            print(f'总价:{all_prices:.2f}元')
            print('您已经退出！拜拜')
            return 0
    
        elif goods_name not in goods_dict:
            print(f"商品 {goods_name} 不存在。")
            continue
    
        else:
            try:
                goods_num = int(input(f"请输入购买 {goods_name} 的数量："))
        
                if goods_num < 1:
                    raise QuantityError('您输入的数量小于1,已自动为您默认购买1份')


                price = goods_dict[goods_name]
                total_price = goods_num * price
                all_goods.update({goods_name:str(goods_num)})
                all_prices += total_price
                print(f"您购买了 {goods_num} 个 {goods_name},总价为:{total_price:.2f} 元")

        
            except QuantityError as error:
                print('出错了,原因是:',error)
                goods_num = 1  
                all_goods.update({goods_name:1})
                print(f"您购买了 1 个 {goods_name},总价为:{goods_dict[goods_name]:.2f} 元")
 

shopping()


'''


def read_address_code_map(file_path):

    address_code_map = {}
    try:
        with open(file_path, 'r', encoding='utf-8') as file:
            for line in file:
                line = line.strip()
                if line:  
                    key, value = line.split(':')
                    address_code_map[key] = value.strip()
    except FileNotFoundError:
        print(f"文件 {file_path} 未找到")
    except Exception as e:
        print(f"读取文件时发生错误: {e}")
    return address_code_map
 
def query_county_by_id_card(id_card, address_code_map):

    if len(id_card) < 6:
        return "身份证号码长度不足，无法查询"
    
    address_code = id_card[:6]
    county = address_code_map.get(address_code)
    
    if county:
        return f"常住户口所在县: {county}"
    else:
        return "未找到对应的地址码"
 

def main():
    file_path = "身份证码值对照表.txt"
    address_code_map = read_address_code_map(file_path)
    
    id_card = input("请输入身份证号码: ")
    result = query_county_by_id_card(id_card, address_code_map)
    print(result)
 
if __name__ == "__main__":
    main()










'''
import os

per_info = []

class TelephoneBook:
    def __init__(self):
        self.filename = '通讯录.txt'
        self.contacts = {}
        self._load_contacts()

    
    def _load_contacts(self):
        if os.path.exists(self.filename):
            with open(self.filename, 'r') as file:
                for line in file:
                    parts = line.strip().split(',')
                    if len(parts) == 4:
                        name, phone, qq, email = parts
                        self.contacts[name] = (phone, qq, email)


    def _save_contacts(self):

        with open(self.filename, 'w') as file:
            for name, (phone, qq, email) in self.contacts.items():
                file.write(f"{name},{phone},{qq},{email}\n")



    def show_menu(self):
        print('***********************************************')
        print('***  1.新建联系人(1)     2.查找联系人(2)     ***')
        print('***             3.退出(0)                   ***')
        print('************************************************')

    def add_info(self):
        per_dict = {}
        name = input('请输入姓名:')
        phone = input('请输入电话号码:')
        qq = input('请输入QQ号:')
        email = input('请输入邮箱:')
        if name in self.contacts:
            print("联系人已存在，请重新输入!")
        else:
            self.contacts[name] = (phone, qq, email)
            self._save_contacts()
            print("联系人添加成功!")

    def show_info(self):
        name = input("请输入要查询的联系人姓名: ")
        if name in self.contacts:
            phone, qq, email = self.contacts[name]
            print(f"姓名: {name}, 电话: {phone}, QQ: {qq}, 邮箱: {email}")
        else:
            print("联系人不存在!")

    def main(self):
        while True:
            self.show_menu()

            n = input('请输入您要执行的操作:')

            if n == '1':
                self.add_info()
            elif n == '2':
                self.show_info()
            elif n == '0':
                print("退出程序!")
                break
            else:
                print("无效选择，请重新输入!")


if __name__ == '__main__':
    book = TelephoneBook()
    book.main()

'''














